// pages/zhuanjiematianjiayuangongye/zhuanjiematianjiayuangongye.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    txtlist: '',
    wordKey: '',
    EMPLOYEE_ID_NEW: '',
    jihuo: '',
    flag: true,
    xiugai: true,
    xinxi: true,
    user: "",

   
  },


  tianjia(e) {
    console.log(e.currentTarget.dataset.itme.EMPLOYEE_ID);

    this.setData({

      EMPLOYEE_ID_NEW: e.currentTarget.dataset.itme.EMPLOYEE_ID,
      xinxi: false,
    })


  },



  search_but() {

    console.log(111);
    if (this.data.flag) {

      this.data.flag = false


      this.setData({
        mealsList: app.globalData.mealsList
      });
      var that = this
      if (that.data.wordKey == "") {
        wx.showToast({
          title: '请输入手机号',
          icon: 'none',
          duration: 2000
        })
      } else {
        wx.request({
          url: app.globalData.interface + '/management/API3_1003_SelectZhuanJieRen ',
          method: 'POSt',
          data: {

            CUSTOMER_TEL: that.data.wordKey,
            OPEN_ID: this.data.openid, //用户OPEN_ID
            session_key: this.data.session_key,
            OPEN_UUID: this.data.jiami,

          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: res => {


            if (res.data.result == "success") {



              console.log(res.data.data);
              wx.showModal({
                title: '温馨提示',
                content: res.data.data,
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后

                  } else { //这里是点击了取消以后
                    console.log('用户点击取消')

                  }
                }
              })
              that.setData({

                jihuo: res.data.data,
                // xinxi: true,
              })


            } else {

              wx.showModal({
                title: '温馨提示',
                content: res.data.data,
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后

                  } else { //这里是点击了取消以后
                    console.log('用户点击取消')

                  }
                }
              })
            }
          }
        })
      }

      setTimeout(() => {
        this.data.flag = true
      }, 3500)


    }

  },











  sihuodong() {
    this.setData({
      EMPLOYEE_ID: app.globalData.mealsList,
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,


    })
    wx.request({
      url: app.globalData.interface + '/management/API3_1001_SelectZhuanJieJiGou',
      method: 'POST',
      data: {
        EMPLOYEE_ID: this.data.EMPLOYEE_ID,
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },


      success: res => {


        if (res.data.result == "success") {

          if (res.data.type == "WANGDIAN") {
            console.log(res.data.data);
            this.setData({
              txtlist: res.data.data
            })
          } else {
            console.log(res.data);
            console.log(res.data.data);
            this.setData({
              txtlist: res.data.data,
            })
          }







        } else {

          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后

              } else { //这里是点击了取消以后
                console.log('用户点击取消')

              }
            }
          })
        }




















      }
    })
  },



  zhuceguanjian() {
    if (this.data.wordKey == "") {
      wx.showToast({
        title: '请先搜索关键人',
        icon: 'none',
        duration: 2000
      })

    } else {

      this.setData({
        EMPLOYEE_ID: app.globalData.mealsList,
        openid: app.globalData.openid,
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        session_key: app.globalData.session_key,


      })
      wx.request({
        url: app.globalData.interface + '/management/API3_1007_AddZhuanJieRen',
        method: 'POST',
        data: {
          EU_NAME: this.data.jihuo.CUSTOMER_NAME,
          EMPLOYEE_ID: this.data.EMPLOYEE_ID_NEW,
          USER_OPEN_ID: this.data.jihuo.OPEN_ID,
          EU_PHONE: this.data.jihuo.CUSTOMER_TEL,
          OPEN_ID: this.data.openid, //用户OPEN_ID
          session_key: this.data.session_key,
          OPEN_UUID: this.data.jiami
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log(res.data);


          let that = this
          console.log(res.data.data);
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
                that.sihuodong()
                that.setData({
                  xinxi: true,
                })


              } else { //这里是点击了取消以后
                console.log('用户点击取消')
                that.sihuodong()
                that.setData({
                  xinxi: true,
                })

              }
            }
          })

        }
      })
    }
  },




  quxiao() {
    this.setData({
      xinxi: true,
    })

  },


  quxiaoaa() {
    this.setData({
      xiugai: true,
    })

  },








  delete(e) {

    console.log(e);
    console.log(e.currentTarget.dataset.itme.user);

    if (e.currentTarget.dataset.itme.user == undefined) {
      console.log(e.currentTarget.dataset.itme);
      this.setData({
        user: e.currentTarget.dataset.itme,
      })
    } else {

      this.setData({
        user: e.currentTarget.dataset.itme.user[0],
      })


    }


    let that = this
    wx.showModal({
      title: '温馨提示',
      content: "是否确认删除关键人",
      success: function (res) {
        if (res.confirm) { //这里是点击了确定以后
          that.deletego()
        } else { //这里是点击了取消以后
          console.log('用户点击取消')
        }
      }
    })
  },





  deletego() {
    wx.request({
      url: app.globalData.interface + '/management/API3_1009_DeleteZhuanJieRen',
      method: 'POST',
      data: {
        EU_ID: this.data.user.EU_ID,
        USER_OPEN_ID: this.data.user.OPEN_ID,

        EU_PHONE: this.data.user.EU_PHONE,
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data);


        let that = this
        console.log(res.data.data);
        wx.showModal({
          title: '温馨提示',
          content: res.data.data,
          success: function (res) {
            if (res.confirm) { //这里是点击了确定以后
              that.sihuodong()


            } else { //这里是点击了取消以后
              console.log('用户点击取消')
              that.sihuodong()

            }
          }
        })

      }
    })

  },


  xiugai(e) {



    console.log(e);
    console.log(e.currentTarget.dataset.itme.user);

    if (e.currentTarget.dataset.itme.user == undefined) {

      this.setData({
        jihuoaa: e.currentTarget.dataset.itme,
        xiugai: false,
      })


    } else {
      console.log(e.currentTarget.dataset.itme);



      this.setData({
        jihuoaa: e.currentTarget.dataset.itme.user[0],
        xiugai: false,
      })

    }



  },


  zhuceguanjianaa() {
    if (this.data.wordKey == "") {
      wx.showToast({
        title: '请先搜索关键人',
        icon: 'none',
        duration: 2000
      })

    } else {

      // console.log(this.data.jihuo.EU_ID);
      // console.log(this.data.jihuo.OPEN_ID);
      // console.log(this.data.jihuo.EU_PHONE);

      this.setData({
        EMPLOYEE_ID: app.globalData.mealsList,
        openid: app.globalData.openid,
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        session_key: app.globalData.session_key,


      })
      wx.request({
        url: app.globalData.interface + '/management/API3_1005_UpdataZhuanJieRen',
        method: 'POST',
        data: {
          EU_ID: this.data.jihuoaa.EU_ID,
          USER_OPEN_ID: this.data.jihuo.OPEN_ID,
          EU_PHONE: this.data.jihuo.CUSTOMER_TEL,
          EU_NAME: this.data.jihuo.CUSTOMER_NAME,
          OPEN_ID: this.data.openid, //用户OPEN_ID
          session_key: this.data.session_key,
          OPEN_UUID: this.data.jiami
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log(res.data);


          let that = this
          console.log(res.data.data);
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
                that.sihuodong()
                that.setData({
                  xiugai: true,
                })


              } else { //这里是点击了取消以后
                console.log('用户点击取消')
                that.sihuodong()


                that.setData({
                  xiugai: true,
                })



              }
            }
          })

        }
      })
    }
  },





  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      EMPLOYEE_ID: app.globalData.mealsList,
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,

    })
    this.sihuodong()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})